using System;
using System.Collections.Generic;
using Voodoo.Sauce.Debugger;
using Voodoo.Sauce.Internal.Utils;

namespace Voodoo.Sauce.Internal.DebugScreen
{
	public static class DebugCustomUtility
	{
		private const string TAG = "DebugCustomUtility";

		private static List<CustomDebugger> _customTypes;

		public static List<CustomDebugger> GetAllCustomDebugger()
		{
			if (_customTypes != null)
			{
				return _customTypes;
			}
			_customTypes = new List<CustomDebugger>();
			foreach (Type type in AssembliesUtils.GetTypes(typeof(CustomDebugger)))
			{
				VoodooLog.LogDebug(Module.COMMON, "DebugCustomUtility", $"CustomDebugger '{type}' found");
				CustomDebugger item = (CustomDebugger)Activator.CreateInstance(type);
				_customTypes.Add(item);
			}
			_customTypes.Sort(SortByIndex);
			return _customTypes;
		}

		private static int SortByIndex(CustomDebugger x, CustomDebugger y)
		{
			int orderIndex = x.GetOrderIndex();
			int orderIndex2 = y.GetOrderIndex();
			if (orderIndex == orderIndex2)
			{
				return string.Compare(x.GetTitle(), y.GetTitle(), StringComparison.Ordinal);
			}
			return orderIndex.CompareTo(orderIndex2);
		}
	}
}
